from django.db import models
from utils.basemodel import BasaModel
from user.models import UserModel,AddressModel
from cake.models import CakesModel

# Create your models here.
class OrderModel(BasaModel):
    user = models.ForeignKey(UserModel,on_delete=models.CASCADE,verbose_name="下单用户")
    address = models.ForeignKey(AddressModel, on_delete=models.CASCADE, null=True, blank=True, verbose_name="收货地址")
    orderno = models.CharField(max_length=100,verbose_name="订单号")
    totalprice = models.DecimalField(max_digits=10, decimal_places=2,verbose_name="顶端总价")
    payprice = models.DecimalField(max_digits=10, decimal_places=2,verbose_name="实际支付金额")
    status = models.IntegerField(verbose_name="订单状态",choices=((0,'未支付'),(1,'已支付'),(2,'已取消'),(3,'已完成')),default=0)
    score = models.IntegerField(verbose_name="积分",default=0)
    paytype = models.IntegerField(verbose_name="支付方式",choices=((0,'支付宝'),(1,'微信'),(2,'银行卡')),default=0)
    paytime = models.DateTimeField(verbose_name="支付时间",null = True,blank=True)
    payno = models.CharField(verbose_name="支付流水号",max_length=100,null=True,blank=True)
    class Meta:
        db_table = "order"
        verbose_name_plural = "订单表"
    def __str__(self):
        return self.orderno
class OrderDetialModel(models.Model):
    order = models.ForeignKey(OrderModel,on_delete=models.CASCADE,verbose_name="所属订单")
    cake = models.ForeignKey(CakesModel,on_delete=models.CASCADE,verbose_name="所选商品")
    cname = models.CharField(verbose_name="商品名称",max_length=100)
    price = models.DecimalField(max_digits=10, decimal_places=2,verbose_name="金额")
    cover = models.CharField(max_length=100,verbose_name="封面")
    class Meta:
        db_table = "order_detail"
        verbose_name_plural = "订单详情表"
    def __str__(self):
        return self.cname
